export function deepestLeavesSum(root: TreeNode | null): number {
  if (!root) return NaN;
  let res = 0;
  const nodeArr: TreeNode[] = [root];
  while (nodeArr.length) {
    const len = nodeArr.length;
    let temp: number = 0;
    for (let index = 0; index < len; index++) {
      const node = nodeArr.shift();
      temp = temp + node.val;
      if (node.left) nodeArr.push(node.left);
      if (node.right) nodeArr.push(node.right);
    }
    res = temp;
  }

  return res;
}
